package com.wuwei.baseproject.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import butterknife.BindView;
import butterknife.OnClick;
import com.githang.statusbar.StatusBarCompat;
import com.union.utils.ToastUtils;
import com.wuwei.baseproject.R;
import com.wuwei.baseproject.adapter.MyAdapter;
import com.wuwei.baseproject.base.BaseCommonActivity;
import com.wuwei.baseproject.basemvp.BaseMvpActivity;
import com.wuwei.baseproject.bean.BaseObjectBean;
import com.wuwei.baseproject.bean.MyFocus;
import com.wuwei.baseproject.config.Constant;
import com.wuwei.baseproject.contact.DemoContact;
import com.wuwei.baseproject.presenter.DemoPresenter;
import com.wuwei.baseproject.utils.ProgressDialog;


import java.util.ArrayList;
import java.util.List;

public class MainCommonActivity extends BaseMvpActivity<DemoPresenter> implements DemoContact.View {

    private List<MyFocus.ListBean> list = new ArrayList<>();

    private MyAdapter myAdapter;

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int getLayoutId() {
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.white), true);
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        mPresenter = new DemoPresenter() ;
        mPresenter.attachView(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        myAdapter = new MyAdapter(this,list);
        recyclerView.setAdapter(myAdapter);
    }

    @OnClick({R.id.btn_start,R.id.btn_click })
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.btn_start://发请求
                mPresenter.getMyFollowList("20", "1","20");
                break;
            case R.id.btn_click://我的消息
                ToastUtils.custom("点击");
                break;
        }
    }



    @Override
    public void onSuccess(MyFocus bean) {
        list.clear();
        if(null != bean && bean.getCode() == 200){
            list.addAll(bean.getList());
            list.addAll(list);
            myAdapter.notifyDataSetChanged();
        }else{
            ToastUtils.custom(bean.getMsg());
        }
    }

    @Override
    public void showLoading() {
        ProgressDialog.getInstance().show(this);
    }

    @Override
    public void hideLoading() {
        ProgressDialog.getInstance().dismiss();
    }

    @Override
    public void onError(Throwable throwable) {
        list.clear();
        ToastUtils.custom("failed");
    }


}
